package com.zhsj.OkeHomeConsumption.ui.fragment.indexhome;

import android.Manifest;
import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.AppBarLayout;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.OrientationHelper;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.amap.api.location.AMapLocation;
import com.amap.api.location.AMapLocationClient;
import com.amap.api.location.AMapLocationClientOption;
import com.amap.api.location.AMapLocationListener;
import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.hjq.bar.TitleBar;
import com.hjq.base.BaseDialog;
import com.hjq.dialog.MessageDialog;
import com.hjq.permissions.OnPermission;
import com.hjq.permissions.Permission;
import com.hjq.permissions.XXPermissions;
import com.nostra13.universalimageloader.utils.L;
import com.orhanobut.hawk.Hawk;
import com.umeng.socialize.ShareAction;
import com.umeng.socialize.UMShareListener;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.umeng.socialize.media.UMImage;
import com.umeng.socialize.media.UMWeb;
import com.umeng.socialize.shareboard.SnsPlatform;
import com.umeng.socialize.utils.ShareBoardlistener;
import com.zhsj.OkeHomeConsumption.R;
import com.zhsj.OkeHomeConsumption.adapter.PersonCenterAdapter;
import com.zhsj.OkeHomeConsumption.common.Constants;
import com.zhsj.OkeHomeConsumption.common.MyApplication;
import com.zhsj.OkeHomeConsumption.common.MyLazyFragment;
import com.zhsj.OkeHomeConsumption.common.OkeHomeConsumptionApi;
import com.zhsj.OkeHomeConsumption.empty.FormalUserInfo;
import com.zhsj.OkeHomeConsumption.empty.MerchantTypeBean;
import com.zhsj.OkeHomeConsumption.empty.Remake;
import com.zhsj.OkeHomeConsumption.empty.ShopListBean;
import com.zhsj.OkeHomeConsumption.event.LoginOutEvent;
import com.zhsj.OkeHomeConsumption.event.LoginUserpanterEvent;
import com.zhsj.OkeHomeConsumption.network.HttpClient;
import com.zhsj.OkeHomeConsumption.network.JsonResponseHandler;
import com.zhsj.OkeHomeConsumption.other.AbastractDragFloatActionButton;
import com.zhsj.OkeHomeConsumption.other.TimeChecker;
import com.zhsj.OkeHomeConsumption.other.TimeOutHandler;
import com.zhsj.OkeHomeConsumption.other.URLEntity;
import com.zhsj.OkeHomeConsumption.ui.activity.FreshfruitActivity;
import com.zhsj.OkeHomeConsumption.ui.activity.HomeActivity;
import com.zhsj.OkeHomeConsumption.ui.activity.IndexCityList;
import com.zhsj.OkeHomeConsumption.ui.activity.LoginActivity;
import com.zhsj.OkeHomeConsumption.ui.activity.PhotoActivity;
import com.zhsj.OkeHomeConsumption.ui.activity.RestaurantActivity;
import com.zhsj.OkeHomeConsumption.ui.activity.RetrunActivity;
import com.zhsj.OkeHomeConsumption.ui.activity.WebActivity;
import com.zhsj.OkeHomeConsumption.ui.activity.wallet.WalletActivity;
import com.zhsj.OkeHomeConsumption.ui.fragment.indexhome.mvp.IndexHomePresenter;
import com.zhsj.OkeHomeConsumption.ui.fragment.indexhome.mvp.IndexHomeUIInterFace;
import com.zhsj.OkeHomeConsumption.utils.GoActivityUtils;
import com.zhsj.OkeHomeConsumption.utils.JsonUtils;
import com.zhsj.OkeHomeConsumption.utils.LogUtils;
import com.zhsj.OkeHomeConsumption.utils.SharedPreferanceUtils;
import com.zhsj.OkeHomeConsumption.utils.SignUtil;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONTokener;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;
import cn.bingoogolapple.bgabanner.BGABanner;

/**
 * author : Xingdx
 * <p>
 * time   : 2018/10/18
 * desc   : 首页
 */
public final class IndexHomeFragment extends MyLazyFragment<HomeActivity> implements IndexHomeUIInterFace, AMapLocationListener {

    @BindView(R.id.abl_test_bar)
    AppBarLayout mAppBarLayout;

    TitleBar mTitleBar;
    //商铺列表
    @BindView(R.id.recommend_recy)
    RecyclerView recommendRecy;
    @BindView(R.id.retrun)
    TextView retrun;
    @BindView(R.id.login_linear)
    LinearLayout loginLinear;
    @BindView(R.id.img1)
    ImageView img1;
    @BindView(R.id.img2)
    ImageView img2;
    @BindView(R.id.img3)
    ImageView img3;
    @BindView(R.id.img4)
    ImageView img4;
    @BindView(R.id.img5)
    ImageView img5;
    @BindView(R.id.img6)
    ImageView img6;
    @BindView(R.id.img7)
    ImageView img7;
    @BindView(R.id.img8)
    ImageView img8;
    @BindView(R.id.img9)
    ImageView img9;
    @BindView(R.id.img10)
    ImageView img10;
    @BindView(R.id.shuiguo1)
    ImageView shuiguo1;
    @BindView(R.id.shuiguo2)
    ImageView shuiguo2;
    @BindView(R.id.shuiguo3)
    ImageView shuiguo3;
    @BindView(R.id.shuiguo4)
    ImageView shuiguo4;
    @BindView(R.id.shuiguo5)
    ImageView shuiguo5;
    @BindView(R.id.shuiguo6)
    ImageView shuiguo6;
    @BindView(R.id.baihuo1)
    ImageView baihuo1;
    @BindView(R.id.baihuo2)
    ImageView baihuo2;
    @BindView(R.id.baihuo3)
    ImageView baihuo3;
    @BindView(R.id.baihuo4)
    ImageView baihuo4;
    @BindView(R.id.baihuo5)
    ImageView baihuo5;
    @BindView(R.id.baihuo6)
    ImageView baihuo6;
    @BindView(R.id.fuzhuang)
    ImageView fuzhuang;
    @BindView(R.id.fuzhuang1)
    ImageView fuzhuang1;
    @BindView(R.id.fuzhuang2)
    ImageView fuzhuang2;
    @BindView(R.id.fuzhuang3)
    ImageView fuzhuang3;
    @BindView(R.id.fuhzuang4)
    ImageView fuhzuang4;
    @BindView(R.id.fuzhuang5)
    ImageView fuzhuang5;
    @BindView(R.id.fuzhuang6)
    ImageView fuzhuang6;
    @BindView(R.id.aiche)
    ImageView aiche;
    @BindView(R.id.aiche1)
    ImageView aiche1;
    @BindView(R.id.aiche2)
    ImageView aiche2;
    @BindView(R.id.aiche3)
    ImageView aiche3;
    @BindView(R.id.xiuxian)
    ImageView xiuxian;
    @BindView(R.id.xiuxian1)
    ImageView xiuxian1;
    @BindView(R.id.xiuxian2)
    ImageView xiuxian2;
    @BindView(R.id.xiuxian3)
    ImageView xiuxian3;
    private AbastractDragFloatActionButton button;

    private ShopAdapter shopadper = null;
    private PersonCenterAdapter mAdapter;
    Unbinder unbinder;
    @BindView(R.id.tv_test_address)
    TextView tvTestAddress;
    @BindView(R.id.tv_test_search)
    TextView tvTestSearch;
    @BindView(R.id.tv_test_right)
    TextView tvTestRight;
    @BindView(R.id.banner_guide_content)
    BGABanner bannerGuideContent;
    //中间的icon
    @BindView(R.id.person_center_recycle)
    RecyclerView personCenterRecycle;

    @BindView(R.id.returnamount_text)
    TextView returnamount_text;
    @BindView(R.id.integral_text)
    TextView integral_text;

    @BindView(R.id.balance_text)
    TextView balance_text;

    private IndexHomePresenter minePersonPresenter;

    private ArrayList<MerchantTypeBean> mMerchantTypeLists = null;
    //店铺
    private List<ShopListBean> ShopList = null;
    /**
     * @Fields mSharedPreferanceUtils : TODO
     */
    private SharedPreferanceUtils mSharePreferanceUtils = null;
    private Remake remake;
    private LinearLayout integral_rel;
    private LinearLayout returnamount_rel;
    private LinearLayout balance_rel;

    private View view;

    private Boolean isLogin = false;

    private FormalUserInfo userInfo = null;
    /**
     * @Fields topurlArr : TODO banner部url标题集合
     */
    private LinkedHashMap<String, String> topUrlTitleArr = null;
    //图片集合
    private ArrayList<String> imageUrlList = null;
    private ArrayList<String> webUrlList = null;
    private ArrayList<Integer> imagemodle = null;
    private List<String> mBannerTitleLists = null;

    private TextView shangjiatuijian_text;

    //定位相关
    //声明AMapLocationClient类对象
    public AMapLocationClient mLocationClient = null;
    //声明AMapLocationClientOption对象
    public AMapLocationClientOption mLocationOption = null;
    //定位城市
    private String districtLocationStr = null;
    private String cityLocationStr = null;
    private String provinceLocationStr = null;
    //选中城市的ID
    private int locationCityId = 0;

    /**
     * 实例化ProgressDrawableAlertDialog
     */
    private BaseDialog pDialogUtils = null;
    /**
     * 计时器
     */
    private TimeChecker timeChecker = null;


    private double userLongitude = 0.0;//用户精度

    private double userLatitude = 0.0;//用户卫度


    public static IndexHomeFragment newInstance() {
        return new IndexHomeFragment();
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_test_a;
    }

    @Override
    protected int getTitleId() {
        return R.id.tb_test_a_bar;
    }

    @Override
    protected void initView() {
        mTitleBar = (TitleBar) findViewById(R.id.tb_test_a_bar);
        tvTestAddress.setSelected(true);
        view = findViewById(R.id.index_integral_view);
        integral_rel =  view.findViewById(R.id.integral_rel);
        returnamount_rel = view.findViewById(R.id.returnamount_rel);
        balance_rel = view.findViewById(R.id.balance_rel);
        button = findViewById(R.id.button);

        button.setOnClickListener(new AbastractDragFloatActionButton.OnClickListener() {
            @Override
            public void onClick() {
                //已缴纳保证金
                switch (userInfo.getLifeUserDTO().getLifeType()) {
                    case 1:
                        //商铺页面
                        EventBus.getDefault().post(new LoginUserpanterEvent(1));
                        break;
                    case 2:
                        //区域运营商页面
                        EventBus.getDefault().post(new LoginUserpanterEvent(2));
                        break;
                }
            }
        });

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            int hasPermission = getActivity().checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION);
            //没有授权
            if (hasPermission != PackageManager.PERMISSION_GRANTED) {
                Permissions();
            } else {
                location();
            }
        }
        Glide.with(getActivity()).load("http://life.okejia.com/life/upload/life/index/t01.png").placeholder(R.drawable.zhanweitu_bg).into(img1);
        Glide.with(getActivity()).load("http://life.okejia.com/life/upload/life/index/t02.png").placeholder(R.drawable.zhanweitu_bg).into(img2);
        Glide.with(getActivity()).load("http://life.okejia.com/life/upload/life/index/b01.png").placeholder(R.drawable.zhanweitu_bg).into(img3);
        Glide.with(getActivity()).load("http://life.okejia.com/life/upload/life/index/p10.png").placeholder(R.drawable.zhanweitu_bg).into(img4);

        Glide.with(getActivity()).load("http://life.okejia.com/life/upload/life/index/p11.png").placeholder(R.drawable.zhanweitu_bg).into(img5);
        Glide.with(getActivity()).load("http://life.okejia.com/life/upload/life/index/p14.png").placeholder(R.drawable.zhanweitu_bg).into(img6);
        Glide.with(getActivity()).load("http://life.okejia.com/life/upload/life/index/p12.png").placeholder(R.drawable.zhanweitu_bg).into(img7);
        Glide.with(getActivity()).load("http://life.okejia.com/life/upload/life/index/p13.png").placeholder(R.drawable.zhanweitu_bg).into(img8);
        Glide.with(getActivity()).load("http://life.okejia.com/life/upload/life/index/p15.png").placeholder(R.drawable.zhanweitu_bg).into(img9);

        Glide.with(getActivity()).load("http://life.okejia.com/life/upload/life/index/p20.png").placeholder(R.drawable.zhanweitu_bg).into(img10);
        Glide.with(getActivity()).load("http://life.okejia.com/life/upload/life/index/p21.png").placeholder(R.drawable.zhanweitu_bg).into(shuiguo1);
        Glide.with(getActivity()).load("http://life.okejia.com/life/upload/life/index/p22.png").placeholder(R.drawable.zhanweitu_bg).into(shuiguo2);
        Glide.with(getActivity()).load("http://life.okejia.com/life/upload/life/index/p23.png").placeholder(R.drawable.zhanweitu_bg).into(shuiguo3);
        Glide.with(getActivity()).load("http://life.okejia.com/life/upload/life/index/p24.png").placeholder(R.drawable.zhanweitu_bg).into(shuiguo4);
        Glide.with(getActivity()).load("http://life.okejia.com/life/upload/life/index/p25.png").placeholder(R.drawable.zhanweitu_bg).into(shuiguo5);
        Glide.with(getActivity()).load("http://life.okejia.com/life/upload/life/index/p26.png").placeholder(R.drawable.zhanweitu_bg).into(shuiguo6);

        Glide.with(getActivity()).load("http://life.okejia.com/life/upload/life/index/p30.png").placeholder(R.drawable.zhanweitu_bg).into(baihuo1);
        Glide.with(getActivity()).load("http://life.okejia.com/life/upload/life/index/p31.png").placeholder(R.drawable.zhanweitu_bg).into(baihuo2);
        Glide.with(getActivity()).load("http://life.okejia.com/life/upload/life/index/p32.png").placeholder(R.drawable.zhanweitu_bg).into(baihuo3);
        Glide.with(getActivity()).load("http://life.okejia.com/life/upload/life/index/p33.png").placeholder(R.drawable.zhanweitu_bg).into(baihuo4);
        Glide.with(getActivity()).load("http://life.okejia.com/life/upload/life/index/p34.png").placeholder(R.drawable.zhanweitu_bg).into(baihuo5);
        Glide.with(getActivity()).load("http://life.okejia.com/life/upload/life/index/p35.png").placeholder(R.drawable.zhanweitu_bg).into(baihuo6);

        Glide.with(getActivity()).load("http://life.okejia.com/life/upload/life/index/p40.png").placeholder(R.drawable.zhanweitu_bg).into(fuzhuang);
        Glide.with(getActivity()).load("http://life.okejia.com/life/upload/life/index/p41.png").placeholder(R.drawable.zhanweitu_bg).into(fuzhuang1);
        Glide.with(getActivity()).load("http://life.okejia.com/life/upload/life/index/p42.png").placeholder(R.drawable.zhanweitu_bg).into(fuzhuang2);
        Glide.with(getActivity()).load("http://life.okejia.com/life/upload/life/index/p43.png").placeholder(R.drawable.zhanweitu_bg).into(fuzhuang3);
        Glide.with(getActivity()).load("http://life.okejia.com/life/upload/life/index/p44.png").placeholder(R.drawable.zhanweitu_bg).into(fuhzuang4);
        Glide.with(getActivity()).load("http://life.okejia.com/life/upload/life/index/p45.png").placeholder(R.drawable.zhanweitu_bg).into(fuzhuang5);
        Glide.with(getActivity()).load("http://life.okejia.com/life/upload/life/index/p46.png").placeholder(R.drawable.zhanweitu_bg).into(fuzhuang6);

        Glide.with(getActivity()).load("http://life.okejia.com/life/upload/life/index/p50.png").placeholder(R.drawable.zhanweitu_bg).into(aiche);
        Glide.with(getActivity()).load("http://life.okejia.com/life/upload/life/index/p51.png").placeholder(R.drawable.zhanweitu_bg).into(aiche1);
        Glide.with(getActivity()).load("http://life.okejia.com/life/upload/life/index/p52.png").placeholder(R.drawable.zhanweitu_bg).into(aiche2);
        Glide.with(getActivity()).load("http://life.okejia.com/life/upload/life/index/p53.png").placeholder(R.drawable.zhanweitu_bg).into(aiche3);

        Glide.with(getActivity()).load("http://life.okejia.com/life/upload/life/index/p60.png").placeholder(R.drawable.zhanweitu_bg).into(xiuxian);
        Glide.with(getActivity()).load("http://life.okejia.com/life/upload/life/index/p61.png").placeholder(R.drawable.zhanweitu_bg).into(xiuxian1);
        Glide.with(getActivity()).load("http://life.okejia.com/life/upload/life/index/p62.png").placeholder(R.drawable.zhanweitu_bg).into(xiuxian2);
        Glide.with(getActivity()).load("http://life.okejia.com/life/upload/life/index/p63.png").placeholder(R.drawable.zhanweitu_bg).into(xiuxian3);

    }

    //动态权限申请

    public void Permissions() {
        XXPermissions.with(getActivity())
                //.constantRequest() //可设置被拒绝后继续申请，直到用户授权或者永久拒绝
                //.permission(Permission.SYSTEM_ALERT_WINDOW, Permission.REQUEST_INSTALL_PACKAGES) //支持请求6.0悬浮窗权限8.0请求安装权限
                .permission(Permission.ACCESS_FINE_LOCATION) //不指定权限则自动获取清单中的危险权限
                .request(new OnPermission() {

                    @Override
                    public void hasPermission(List<String> granted, boolean isAll) {
                        location();
                    }

                    @Override
                    public void noPermission(List<String> denied, boolean quick) {
                        toast("定位权限被拒绝");
                        minePersonPresenter.ShopListGet(mSharePreferanceUtils.getSelectCityId(), "", "");
                    }
                });

    }


    @Override
    protected void initData() {

        mMerchantTypeLists = new ArrayList<MerchantTypeBean>();
        shangjiatuijian_text = findViewById(R.id.shangjiatuijian_text);
        mSharePreferanceUtils = new SharedPreferanceUtils(getActivity());
        minePersonPresenter = new IndexHomePresenter(getActivity(), this);
        pDialogUtils = new BaseDialog(getActivity());
        timeChecker = new TimeChecker(TimeOutHandler.timeOutHandler, Constants.TIME_OUT);
        GridLayoutManager gridlayoutManager = new GridLayoutManager(getActivity(), 4);
        gridlayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        personCenterRecycle.setLayoutManager(gridlayoutManager);
        personCenterRecycle.setHasFixedSize(true);
        personCenterRecycle.setNestedScrollingEnabled(false); // scrollview 嵌套滑动

        LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
        //设置布局管理器
        recommendRecy.setLayoutManager(layoutManager);
        //设置为垂直布局，这也是默认的
        layoutManager.setOrientation(OrientationHelper.VERTICAL);
        recommendRecy.setNestedScrollingEnabled(false);//禁止滑动
        minePersonPresenter.IndexBannerGET(0);
        tvTestAddress.setText(mSharePreferanceUtils.getcityName().equals("") ? "" : mSharePreferanceUtils.getcityName());
        if (mSharePreferanceUtils.getToken().equals("")) {
            button.setVisibility(View.GONE);
            isLogin = false;
            loginLinear.setVisibility(View.VISIBLE);
        } else {
            isLogin = true;
            loginLinear.setVisibility(View.GONE);
            minePersonPresenter.DetailGet();
            minePersonPresenter.WalletGet();

        }
        tvTestRight.setText("");
        tvTestRight.setBackgroundResource((R.mipmap.gengduo));
        service();
        inieLinster();

    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onLoginOutEvent(LoginOutEvent event) {
        if (event.getTag() == 1) {
            //login out
            initData();
            isLogin = false;
        } else {
            initData();

        }
    }


    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onEvent(FormalUserInfo formalUserInfo) {
        Constants.TOKEN = formalUserInfo.getToken();
        Hawk.put(Constants.SHARED_PERFERENCE_USERINFO, formalUserInfo);
        mSharePreferanceUtils.setToken(formalUserInfo.getToken());
    }

    private void service() {
        minePersonPresenter.MerchantTypeGet("", mSharePreferanceUtils.getSelectCityId() + "");
//        if (mSharePreferanceUtils.getSelectCityId() != 0) {
//        shangjiatuijian_text.setVisibility(View.VISIBLE);
//        }

    }

    private void inieLinster() {

        integral_rel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //积分兑换
                if (mSharePreferanceUtils.getToken().equals("")) {
                    startActivity(LoginActivity.class);
                } else {
                    Intent intent = new Intent(getActivity(), RetrunActivity.class);
                    intent.putExtra("title_flage", 1);
                    intent.putExtra("fanhuan_price", integral_text.getText().toString());
                    startActivity(intent);
                }
            }
        });
        returnamount_rel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //返还额度
                if (mSharePreferanceUtils.getToken().equals("")) {
                    startActivity(LoginActivity.class);
                } else {
                    Intent intent = new Intent(getActivity(), RetrunActivity.class);
                    intent.putExtra("title_flage", 0);
                    intent.putExtra("fanhuan_price", returnamount_text.getText().toString());
                    startActivity(intent);
                }
            }
        });
        balance_rel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //可提现金额
                if (mSharePreferanceUtils.getToken().equals("")) {
                    startActivity(LoginActivity.class);
                } else {
                    Intent intent = new Intent(getActivity(), WalletActivity.class);
                    intent.putExtra("remakeblance", 0);
                    startActivity(intent);
                }

            }
        });

        bannerGuideContent.setDelegate(new BGABanner.Delegate<ImageView, String>() {
            @Override
            public void onBannerItemClick(BGABanner banner, ImageView itemView, String model, int position) {
                startActivity(new Intent(getActivity(), WebActivity.class).putExtra("url", webUrlList.get(position)));
//                Toast.makeText(banner.getContext(), "点击了" + position, Toast.LENGTH_SHORT).show();
            }
        });


    }

    @Override
    public boolean isStatusBarEnabled() {
        // 使用沉浸式状态栏
        return !super.isStatusBarEnabled();
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // TODO: inflate a fragment view
        View rootView = super.onCreateView(inflater, container, savedInstanceState);
        unbinder = ButterKnife.bind(this, rootView);
        return rootView;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }




    /**
     * 获取经营类型
     */
    @Override
    public void MerchantTypeGet(String context) {
        try {
            JSONTokener jsonT = new JSONTokener(context);
            JSONObject jsonOBJ = (JSONObject) jsonT.nextValue();
            String code = jsonOBJ.optString("code");
            String message = jsonOBJ.optString("message");
            if (code.equals("N000000")) {
                JSONArray jsonarr = jsonOBJ.optJSONArray("data");
                // 数据对接正常
                mMerchantTypeLists = new Gson().fromJson(jsonarr.toString(), new
                        TypeToken<ArrayList<MerchantTypeBean>>() {
                        }.getType());
                mAdapter = new PersonCenterAdapter(getActivity(), mMerchantTypeLists);
                personCenterRecycle.setAdapter(mAdapter);
                setRecycleViewOnClick();
            } else if (code.equals(Constants.STATUSTOKENERROR)) {
                // token过期
                if (!message.equals("null")) {
                    log(message);
                }
            } else {
                if (!message.equals("null")) {
                    log(message);
                }
            }
        } catch (JSONException ex) {
            Log.e("MerchantTypeGet", "获取经营类型异常");
        }
    }


    @Override
    public void ShopListGet(String context) {
        try {
            JSONTokener jsonT = new JSONTokener(context);
            JSONObject jsonOBJ = (JSONObject) jsonT.nextValue();
            String code = jsonOBJ.optString("code");
            String message = jsonOBJ.optString("message");
            if (code.equals("N000000")) {
                JSONArray jsonarr = jsonOBJ.optJSONArray("data");
                // 数据对接正常
                ShopList = new Gson().fromJson(jsonarr.toString(), new
                        TypeToken<ArrayList<ShopListBean>>() {
                        }.getType());
                shopadper = new ShopAdapter();
                recommendRecy.setAdapter(shopadper);
            } else if (code.equals(Constants.STATUSTOKENERROR)) {
                // token过期
                if (!message.equals("null")) {
                    shangjiatuijian_text.setVisibility(View.GONE);
                    log(message);
                }
            } else {
                if (!message.equals("null")) {
                    shangjiatuijian_text.setVisibility(View.GONE);
                    log(message);
                }
            }
        } catch (JSONException ex) {
            Log.e("ShopListGet", "获取推荐店铺异常");
        }
    }

    @Override
    public void WalletGet(String context) {
        try {
            JSONTokener jsonT = new JSONTokener(context);
            JSONObject jsonOBJ = (JSONObject) jsonT.nextValue();
            String code = jsonOBJ.optString("code");
            String message = jsonOBJ.optString("message");
            if (code.equals("N000000")) {
                JSONObject jsonobj = jsonOBJ.optJSONObject("data");
                // 数据对接正常
                if (jsonobj != null) {
                    remake = JsonUtils.object(jsonobj.toString(), Remake.class);
                    returnamount_text.setText(remake.getBackAmount() + "");
                    balance_text.setText(remake.getLianLianBalance() + "");
                    integral_text.setText(remake.getIntegral() + "");
                }


            } else if (code.equals(Constants.STATUSTOKENERROR)) {
                // token过期
                if (!message.equals("null")) {
                    log(message);
                    log(message);
                }
            } else {
                if (!message.equals("null")) {
                    log(message);
                }
            }
        } catch (JSONException ex) {
            Log.e("WalletGet", "钱包");
        }
    }

    @Override
    public void IndexBannerGET(String context) {
        try {
            JSONTokener jsonT = new JSONTokener(context);
            JSONObject jsonOBJ = (JSONObject) jsonT.nextValue();
            String code = jsonOBJ.optString("code");
            String message = jsonOBJ.optString("message");
            if (code.equals("N000000")) {
                // 首页Banner数据
                JSONArray optJSONArray = jsonOBJ.optJSONArray("data");
                topUrlTitleArr = new LinkedHashMap<String, String>();
                imageUrlList = new ArrayList<String>();
                webUrlList = new ArrayList<>();
                imagemodle = new ArrayList<>();
                mBannerTitleLists = new ArrayList<String>();
                // 首页数据
                for (int i = 0; i < optJSONArray.length(); i++) {
                    final JSONArray imgPathArray = optJSONArray.optJSONObject(i).optJSONArray("imgPath");
                    if (!imageUrlList.contains(imgPathArray.optString(0))) {
                        imageUrlList.add(imgPathArray.optString(0));
                    }
                    if (!topUrlTitleArr.containsKey(optJSONArray.optJSONObject(i).optString("title")) &&
                            !topUrlTitleArr.containsValue(optJSONArray.optJSONObject(i).optString("url"))) {
                        topUrlTitleArr.put(optJSONArray.optJSONObject(i).optString("title"),
                                optJSONArray.optJSONObject(i).optString("url"));
                        mBannerTitleLists.add(optJSONArray.optJSONObject(i).optString("title"));
                        imagemodle.add(optJSONArray.optJSONObject(i).optInt("module"));
                        webUrlList.add(optJSONArray.optJSONObject(i).optString("url"));
                    }

                }
                //设置图片集合
                bannerGuideContent.setAdapter(new BGABanner.Adapter<ImageView, String>() {
                    @Override
                    public void fillBannerItem(BGABanner banner, ImageView itemView, String model, int position) {
                        Glide.with(getActivity())
                                .load(model)
//                                .placeholder(R.drawable.homebanneryi)
                                .error(R.drawable.homebannerer)
                                .centerCrop()
                                .dontAnimate()
                                .into(itemView);
                    }
                });

                bannerGuideContent.setData(imageUrlList, mBannerTitleLists);
            } else if (code.equals(Constants.STATUSTOKENERROR)) {
                // token过期
                if (!message.equals("null")) {
                }
            } else {
                if (!message.equals("null")) {
                }

            }
        } catch (Exception ex) {
            LogUtils.e("IndexFragemnt banner", "数据获取异常 ");
        }


    }

    @Override
    public void DetailGet(String context) {
        try {
            JSONTokener jsonT = new JSONTokener(context);
            JSONObject jsonOBJ = (JSONObject) jsonT.nextValue();
            String code = jsonOBJ.optString("code");
            String message = jsonOBJ.optString("message");
            if (code.equals("N000000")) {
                JSONObject dataLoginobj = jsonOBJ.optJSONObject("data");
                userInfo = JsonUtils.object(dataLoginobj.toString(), FormalUserInfo.class);
                Hawk.put(Constants.SHARED_PERFERENCE_USERINFO, userInfo);

                //public enum DepositStatusType{
                //    /**支付及退款状态*/
                //    TO_BE_PAID(0,"待支付"),PAID(1,"已支付"),
                //    APPLY_4_REFUND(3,"申请退款"),REFUNDED(4,"退款待交");
                if (userInfo.getLifeUserDTO().getDepositStatusType() == 3 || userInfo.getLifeUserDTO().getDepositStatusType() == 4) {
                    button.setVisibility(View.GONE);
                } else {
                    switch (userInfo.getLifeUserDTO().getLifeType()) {
                        case 1:
                            //商铺页面
                            button.setVisibility(View.VISIBLE);
//                        EventBus.getDefault().post(new LoginUserpanterEvent(1));
                            break;
                        case 2:
                            //区域运营商页面
                            button.setVisibility(View.VISIBLE);
//                        EventBus.getDefault().post(new LoginUserpanterEvent(2));
                            break;
                    }
                }
            } else {
                if (!message.equals("null")) {
                    toast("message");
                    TimeOutHandler.pDialogUtils.dismiss();
                }
            }
        } catch (JSONException ex) {
            TimeOutHandler.pDialogUtils.dismiss();
        }
    }

    public void setRecycleViewOnClick() {
        mAdapter.setOnItemClickLitener(new PersonCenterAdapter.OnItemClickLitener() {
            @Override
            public void GoItemInfo(int position) {


                if (mMerchantTypeLists.get(position).getId() == 45) {
                    if (checkPackInfo("com.android.okehome")) {
                        Intent intent = MyApplication.getContext().getPackageManager().getLaunchIntentForPackage("com.android.okehome");
                        if (intent != null) {
                            intent.putExtra("type", "110");
                            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                            startActivity(intent);
                        }
                    } else {
                        final AlertDialog alertDialog = new AlertDialog.Builder(getActivity()).create();
                        alertDialog.show();
                        Window window = alertDialog.getWindow();
                        window.setContentView(R.layout.alertdialog_item);
                        TextView yes = window.findViewById(R.id.yes);
                        yes.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                Intent intent4 = new Intent(getActivity(), WebActivity.class)
                                        .putExtra("url", "http://okejia.com/temp/app2/b/8.html");
                                startActivity(intent4);
                            }
                        });
                        TextView no = window.findViewById(R.id.no);
                        no.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                alertDialog.dismiss();
                            }
                        });
                        alertDialog.setCancelable(true);//点击事件点击外部消失

                    }

                } else {
                    // 店铺页面
//                    if (mMerchantTypeLists.get(position).getShopCopartnerNum() == 0) {
//                        toast("正在招募中");
//                        return;
//                    }
                    Intent intent = new Intent(getActivity(), FreshfruitActivity.class);
                    intent.putExtra("mMerchantTypeLists", mMerchantTypeLists);
                    intent.putExtra("position", position);
                    intent.putExtra("titlename", mMerchantTypeLists.get(position).getName());
                    startActivity(intent);
                }
            }
        });

    }

    @OnClick({R.id.img1, R.id.img2, R.id.img3, R.id.img4, R.id.img5, R.id.img6, R.id.img7, R.id.img8, R.id.img9, R.id.img10, R.id.shuiguo1, R.id.shuiguo2, R.id.shuiguo3, R.id.shuiguo4, R.id.shuiguo5, R.id.shuiguo6, R.id.baihuo1, R.id.baihuo2, R.id.baihuo3, R.id.baihuo4, R.id.baihuo5, R.id.baihuo6, R.id.fuzhuang, R.id.fuzhuang1, R.id.fuzhuang2, R.id.fuzhuang3, R.id.fuhzuang4, R.id.fuzhuang5, R.id.fuzhuang6, R.id.aiche, R.id.aiche1, R.id.aiche2, R.id.aiche3, R.id.xiuxian, R.id.xiuxian1, R.id.xiuxian2, R.id.xiuxian3
    ,R.id.tv_test_address, R.id.tv_test_search, R.id.tv_test_right, R.id.login_text})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.img1:
                Intent intent4 = new Intent(getActivity(), WebActivity.class)
                        .putExtra("url", "http://www.okejia.com/h5/article/1.html");
                startActivity(intent4);
                break;
            case R.id.img2:
                Intent intent = new Intent(getActivity(), WebActivity.class)
                        .putExtra("url", "http://www.okejia.com/h5/article/3.html");
                startActivity(intent);
                break;
            case R.id.img3:toast("正在招募中");
                break;
            case R.id.img4:toast("正在招募中");
                break;
            case R.id.img5:toast("正在招募中");
                break;
            case R.id.img6:toast("正在招募中");
                break;
            case R.id.img7:toast("正在招募中");
                break;
            case R.id.img8:toast("正在招募中");
                break;
            case R.id.img9:toast("正在招募中");
                break;
            case R.id.img10:toast("正在招募中");
                break;
            case R.id.shuiguo1:toast("正在招募中");
                break;
            case R.id.shuiguo2:toast("正在招募中");
                break;
            case R.id.shuiguo3:toast("正在招募中");
                break;
            case R.id.shuiguo4:toast("正在招募中");
                break;
            case R.id.shuiguo5:toast("正在招募中");
                break;
            case R.id.shuiguo6:toast("正在招募中");
                break;
            case R.id.baihuo1:toast("正在招募中");
                break;
            case R.id.baihuo2:toast("正在招募中");
                break;
            case R.id.baihuo3:toast("正在招募中");
                break;
            case R.id.baihuo4:toast("正在招募中");
                break;
            case R.id.baihuo5:toast("正在招募中");
                break;
            case R.id.baihuo6:toast("正在招募中");
                break;
            case R.id.fuzhuang:toast("正在招募中");
                break;
            case R.id.fuzhuang1:toast("正在招募中");
                break;
            case R.id.fuzhuang2:toast("正在招募中");
                break;
            case R.id.fuzhuang3:toast("正在招募中");
                break;
            case R.id.fuhzuang4:toast("正在招募中");
                break;
            case R.id.fuzhuang5:toast("正在招募中");
                break;
            case R.id.fuzhuang6:toast("正在招募中");
                break;
            case R.id.aiche:toast("正在招募中");
                break;
            case R.id.aiche1:toast("正在招募中");
                break;
            case R.id.aiche2:
                toast("正在招募中");
                break;
            case R.id.aiche3:
                toast("正在招募中");
                break;
            case R.id.xiuxian:
                toast("正在招募中");
                break;
            case R.id.xiuxian1:
                toast("正在招募中");
                break;
            case R.id.xiuxian2:
                toast("正在招募中");
                break;
            case R.id.xiuxian3:
                toast("正在招募中");
                break;
            case R.id.tv_test_address:
                if (TextUtils.isEmpty(provinceLocationStr) && TextUtils.isEmpty(cityLocationStr) && TextUtils.isEmpty(districtLocationStr)) {
                    startActivityForResult(new Intent(getActivity(), IndexCityList.class)
                            .putExtra("locationcity", "定位失败")
                            .putExtra("locationCityId", locationCityId), 0);
                } else {
                    startActivityForResult(new Intent(getActivity(), IndexCityList.class)
                            .putExtra("locationcity", provinceLocationStr + "-" + cityLocationStr + "-" + districtLocationStr)
                            .putExtra("locationCityId", locationCityId), 0);
                }
                break;
            case R.id.tv_test_search:

                startActivity(StoreSearchActivity.class);
                break;
            case R.id.tv_test_right:
                if (mSharePreferanceUtils.getToken().equals("")) {
                    startActivity(LoginActivity.class);
                } else {
                    shareApp("聚联惠", "聚联惠", OkeHomeConsumptionApi.ELVDOU_BASEURL_H5 + "app/h5/platform/16.html");
                }
                break;
            case R.id.login_text:
                startActivity(LoginActivity.class);
                break;

        }
    }


    public class ShopAdapter extends BaseQuickAdapter<ShopListBean, BaseViewHolder> {
        public ShopAdapter() {
            super(R.layout.item_index_shop, ShopList);
        }

        @Override
        protected void convert(BaseViewHolder helper, final ShopListBean item) {
            helper.setText(R.id.title_text, item.getShopName())
                    .setText(R.id.city_text, item.getDistricCountryName() + " | " + distanceFormat(item.getDistanceMeter()))
                    .setText(R.id.address_text, item.getAddress())
                    .setOnClickListener(R.id.lin, new AdapterView.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            //跳转首页推荐店铺详情
                            Intent intent = new Intent(getActivity(), RestaurantActivity.class);
                            intent.putExtra("itemid", item.getId());
                            startActivity(intent);
                        }

                    });
            RecyclerView item_shop_recy = helper.itemView.findViewById(R.id.item_shop_recy);
            LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
            //设置布局管理器
            item_shop_recy.setLayoutManager(layoutManager);

            layoutManager.setOrientation(OrientationHelper.HORIZONTAL);
            //设置Adapter
            ItemShopAdapter shopadper = new ItemShopAdapter(item.getShopInsidePicList());
            item_shop_recy.setAdapter(shopadper);

        }
    }

    public class ItemShopAdapter extends BaseQuickAdapter<String, BaseViewHolder> {

        public ItemShopAdapter(@Nullable List<String> data) {
            super(R.layout.item_shop_recy_img, data);
        }

        @Override
        protected void convert(@NonNull BaseViewHolder helper, final String item) {
            ImageView img = helper.itemView.findViewById(R.id.image);
            Glide.with(getActivity()).load(item).placeholder(R.drawable.zhanweitu_bg).into(img);
            img.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    GoActivityUtils.GoPhotoViewpagerActivity
                            (PhotoActivity.createCircleIntent(getActivity(), Collections.singletonList(item), 0, "1")
                                    , getActivity()
                                    , v
                            );
                }
            });
        }
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        switch (requestCode) {
            case 0:
                //城市列表返回
                initData();
                tvTestAddress.setText(mSharePreferanceUtils.getcityName().equals("") ? "" : mSharePreferanceUtils.getcityName());
                if (mSharePreferanceUtils.getSelectCityId() == 0) {
                    mMerchantTypeLists.clear();
                    if (mAdapter != null) {
                        mAdapter.notifyDataSetChanged();
                    }
                }
                break;
        }
    }

    /**
     * 检查包是否存在
     *
     * @param packname
     * @return
     */
    private boolean checkPackInfo(String packname) {
        PackageInfo packageInfo = null;
        try {
            packageInfo = MyApplication.getContext().getPackageManager().getPackageInfo(packname, 0);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        return packageInfo != null;
    }

    /**
     * @Title: shareApp @Description: TODO @param @param title
     * 分享标题 @param @param content 分享内容 @param @param url 分享链接 @return
     * void @throws
     */
    private void shareApp(String title, String content, String url) {
        final UMWeb web = new UMWeb(url);
        web.setTitle(title);//标题
        web.setDescription(content);//描述
        web.setThumb(new UMImage(getActivity(), R.mipmap.androidicon1));
        new ShareAction(getActivity())
                .setDisplayList(SHARE_MEDIA.WEIXIN, SHARE_MEDIA.WEIXIN_CIRCLE)
                .setShareboardclickCallback(new ShareBoardlistener() {
                    @Override
                    public void onclick(SnsPlatform snsPlatform, SHARE_MEDIA share_media) {
                        new ShareAction(getActivity()).setPlatform(share_media).setCallback(umShareListener)
                                .withMedia(web)
                                .share();
                    }
                }).open();
    }

    /**
     * @Fields umShareListener : TODO 监听分享后的状态
     */
    private UMShareListener umShareListener = new UMShareListener() {
        @Override
        public void onStart(SHARE_MEDIA share_media) {
        }

        @Override
        public void onResult(SHARE_MEDIA platform) {
            toast("分享活动成功啦");

        }

        @Override
        public void onError(SHARE_MEDIA platform, Throwable t) {

            toast("分享失败啦");
        }

        @Override
        public void onCancel(SHARE_MEDIA platform) {

            toast("分享取消了");
        }
    };

    private void location() {
        //初始化定位
        mLocationClient = new AMapLocationClient(MyApplication.getContext());
        //设置定位回调监听
        mLocationClient.setLocationListener(this);
        //初始化AMapLocationClientOption对象
        mLocationOption = new AMapLocationClientOption();
        //设置定位模式为AMapLocationMode.Battery_Saving，低功耗模式。
        mLocationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Battery_Saving);
        //获取一次定位结果：
        //该方法默认为false。
        mLocationOption.setOnceLocation(true);

        //获取最近3s内精度最高的一次定位结果：
        //设置setOnceLocationLatest(boolean b)接口为true，启动定位时SDK会返回最近3s内精度最高的一次定位结果。如果设置其为true，setOnceLocation(boolean b)接口也会被设置为true，反之不会，默认为false。
        mLocationOption.setOnceLocationLatest(true);
        //给定位客户端对象设置定位参数
        mLocationClient.setLocationOption(mLocationOption);
        //启动定位
        mLocationClient.startLocation();
    }

    //声明定位回调监听器
    @Override
    public void onLocationChanged(AMapLocation aMapLocation) {
        if (aMapLocation != null) {
            if (aMapLocation.getErrorCode() == 0) {
                //可在其中解析amapLocation获取相应内容。
//                amapLocation.getCountry();//国家信息
//                amapLocation.getProvince();//省信息
//                amapLocation.getCity();//城市信息
//                amapLocation.getDistrict();//城区信息

                userLatitude = aMapLocation.getLatitude();//获取纬度
                userLongitude = aMapLocation.getLongitude();//获取经度
                Hawk.put("userLatitude", userLatitude);

                Hawk.put("userLongitude", userLongitude);
                provinceLocationStr = aMapLocation.getProvince();
                cityLocationStr = aMapLocation.getCity();
                districtLocationStr = aMapLocation.getDistrict();

                LogUtils.e("定位信息", aMapLocation.toString());

                PostCityName(districtLocationStr);
                mLocationClient.stopLocation();//停止定位后，本地定位服务并不会被销毁
                minePersonPresenter.ShopListGet(mSharePreferanceUtils.getSelectCityId(), String.valueOf(userLongitude), String.valueOf(userLatitude));

            } else {
                //定位失败时，可通过ErrCode（错误码）信息来确定失败的原因，errInfo是错误信息，详见错误码表。
                Log.e("AmapError", "location Error, ErrCode:"
                        + aMapLocation.getErrorCode() + ", errInfo:"
                        + aMapLocation.getErrorInfo());

                minePersonPresenter.ShopListGet(mSharePreferanceUtils.getSelectCityId(), "", "");

            }
        }
    }

    /**
     * 获取定位城市的id
     */
    public void PostCityName(String name) {
        // TODO Auto-generated method stub
        // post传参使用的HashMap
        HashMap<String, String> paramMaps = new HashMap<String, String>();
        // 生成sign值所使用的HashMap
        final HashMap<String, String> mArticleDiaryHashMap = new HashMap<String, String>();
        // mParamHashMap.put("token", Constants.TOKEN);
        mArticleDiaryHashMap.put("v", Constants.APPVERSION);
        mArticleDiaryHashMap.put("t", Constants.TIME);
        mArticleDiaryHashMap.put("deviceToken", Constants.DEVICETOKEN);
        mArticleDiaryHashMap.put("client", Constants.CLIENT);
        LogUtils.e("ArticleDiaryPost time =", Constants.TIME);
        mArticleDiaryHashMap.put("deviceId", URLEntity.getInstance().getImei());
        mArticleDiaryHashMap.put("platform", Constants.PLAFORM);
        mArticleDiaryHashMap.put("name", name);

        paramMaps.put("name", name);
        // 网络计时器及线程
        TimeOutHandler.pDialogUtils = pDialogUtils;
        timeChecker.start();
        // 获取sign签名
        Constants.SIGN = SignUtil.getInstance().getSign(mArticleDiaryHashMap);
        HttpClient.post(OkeHomeConsumptionApi.ELVDOU_POSICITY, paramMaps, new JsonResponseHandler() {

            @Override
            public void onSuccess(int statusCode, String content) {
                // TODO Auto-generated method stub
                super.onSuccess(statusCode, content);
                timeChecker.check();
                TimeOutHandler.pDialogUtils = null;
                LogUtils.e("城市名称", content);
                try {
                    JSONTokener jsonT = new JSONTokener(content);
                    JSONObject jsonOBJ = (JSONObject) jsonT.nextValue();
                    String code = jsonOBJ.optString("code");
                    String message = jsonOBJ.optString("message");
                    if (code.equals("N000000")) {
                        final JSONObject jsonObject = jsonOBJ.optJSONObject("data");
                        if (jsonObject != null) {
                            tvTestAddress.setText(provinceLocationStr + "-" + cityLocationStr + "-" + districtLocationStr);
                            locationCityId = jsonObject.optInt("id");
                            minePersonPresenter.MerchantTypeGet("", String.valueOf(locationCityId));
                            if (locationCityId != 0) {
//                                shangjiatuijian_text.setVisibility(View.VISIBLE);
                            }
                        } else {
                            //该城市未开通
                            new MessageDialog.Builder(getActivity())
                                    .setMessage("当前定位城市未开通服务\n是否切换城市")
                                    .setConfirm("切换")
                                    .setCancel("取消") // 设置 null 表示不显示取消按钮
                                    .setCancelable(false)
                                    //.setAutoDismiss(false) // 设置点击按钮后不关闭对话框
                                    .setListener(new MessageDialog.OnListener() {

                                        @Override
                                        public void onConfirm(Dialog dialog) {
                                            startActivityForResult(new Intent(getActivity(), IndexCityList.class).putExtra("locationcity", provinceLocationStr + "-" + cityLocationStr + "-" + districtLocationStr)
                                                    .putExtra("locationCityId", locationCityId), 0);
                                        }

                                        @Override
                                        public void onCancel(Dialog dialog) {

                                        }
                                    })
                                    .show();
                        }

                    } else if (code.equals(Constants.STATUSTOKENERROR)) {
                        // token过期
                        if (!message.equals("null")) {
//                            showShortToast(message);
                        }
                    } else {
                        if (!message.equals("null")) {
//                            showShortToast(message);
                        }
                    }
                } catch (Exception ex) {
                    LogUtils.e("ArticleDiaryPost", ex.toString());
                }
            }

            @Override
            public void onFailure(Throwable e) {
                // TODO Auto-generated method stub
                super.onFailure(e);
                timeChecker.check();
                pDialogUtils.dismiss();
                TimeOutHandler.pDialogUtils = null;
                LogUtils.e("onFailure", "" + e.toString());
            }
        });
    }

    /**
     * 距离只保留两位小数
     *
     * @param distance 以米为单位
     * @return
     */
    public static String distanceFormat(double distance) {
        String str;
        double value = distance;
        if (distance >= 1000) {
            value = value / 1000;
            str = "KM";
        } else {
            str = "M";
        }
        return value + str;
    }

}